import gtk

class filedialog(object):
    def __init__(self,title,style):
        if style == "save":
            self.file_dialog = gtk.FileChooserDialog(title=title
                            , action=gtk.FILE_CHOOSER_ACTION_SAVE
                            , buttons=(gtk.STOCK_CANCEL
                                , gtk.RESPONSE_CANCEL
                                , gtk.STOCK_SAVE
                                , gtk.RESPONSE_OK))
        elif style == "open":
            self.file_dialog = gtk.FileChooserDialog(title=title
                                , action=gtk.FILE_CHOOSER_ACTION_OPEN
                                , buttons=(gtk.STOCK_CANCEL
                                                , gtk.RESPONSE_CANCEL
                                                , gtk.STOCK_OPEN
                                                , gtk.RESPONSE_OK))

    def add_game_filter(self):
        """Create and add the filter"""
        filter = gtk.FileFilter()
        filter.set_name("Game Baker Game")
        filter.add_pattern("*.gb")
        self.file_dialog.add_filter(filter)

    def add_sprite_filter(self):
        """Create and add the filter"""
        filter = gtk.FileFilter()
        filter.set_name("Game Baker Sprite")
        filter.add_pattern("*.gbs")
        self.file_dialog.add_filter(filter)

    def add_all_files_filter(self):
        """Create and add the 'all files' filter"""
        filter = gtk.FileFilter()
        filter.set_name("All files")
        filter.add_pattern("*")
        self.file_dialog.add_filter(filter)

    def run(self):
        return self.file_dialog.run()

    def destroy(self):
        return self.file_dialog.destroy()

    def get_filename(self):
        return self.file_dialog.get_filename()

